<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@include file="/taglibs.jsp"%>
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link href="${ctx}/resources/semantic/dist/semantic.min.css" rel="stylesheet" type="text/css" />
<link href="${ctx}/resources/apps.css" rel="stylesheet" type="text/css" />
<script src="${ctx}/resources/semanticui/jquery-2.1.4.min.js"></script>
<script src="${ctx}/resources/semantic/dist/semantic.min.js" type="text/javascript"></script>
<title>完善注册信息</title>
<style type="text/css">
	#next{
		margin:10px;
	}
	#closeit{
		margin:10px;
	}
	.label{
		margin-top:0.3rem;
	}
</style>
</head>
<body>

	<div class="ui segment" id="n-page" style="padding-top:0em;">
		<div class="ui segment" id="n-content" >
			<input type="hidden" id="roleIds" name="roleIds" value="${hunter.roleIds}"  />
			<form class="ui form">
				<p><span style="color: red">*</span>请选择您要注册的账号类型</p>
				<div class="inline fields">
				   <div class="field">
				      <div class="ui radio checkbox">
				        <input type="radio" name="roleIds" id="hunter" value="0" onclick="selectApplyRoleType(this);">
				        <label>猎头</label> 
				      </div>
				    </div>
				    <div class="field">
				      <div class="ui radio checkbox">
				        <input type="radio" name="roleIds" id="adviser" value="1" onclick="selectApplyRoleType(this);">
				        <label>职道顾问</label>
				      </div>
				    </div>
				    <div class="field">
				      <div class="ui radio checkbox">
				        <input type="radio" name="roleIds" id="both"  value="2" onclick="selectApplyRoleType(this);">
				        <label>猎头和顾问</label>
				      </div>
				    </div>
				    <input type="hidden" value="${hunter.roleIds}" id="roleVal" />
				</div>
				<p>1.个人信息</p>

				<div class="field">
					<label><span style="color: red">*</span>姓名</label>
					<div class="ui input">
						<input type="text" name="name" id="name" placeholder="请输入姓名"
							value="${hunter.name}">
					</div>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>英文名</label>
					<div class="ui input">
						<input type="text" name="englishname" id="englishname"
							placeholder="请输入英文名" value="${hunter.englishname}">
					</div>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>身份证</label>
					<div class="ui input">
						<input type="text" name="idnumber" id="idnumber"
							placeholder="请输入身份证" value="${hunter.idnumber}">
					</div>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>电子邮箱</label>
					<div class="ui input">
						<input type="email" name="cemail" id="cemail"
							   placeholder="请输入您的邮箱" value="${hunter.email}">
					</div>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>城市</label> <select name="cityId" id="cityId"
																			   class="ui search dropdown">
					<option value="">请输入所在城市</option>
					<c:forEach items="${cities}" var="city">
						<c:choose>
							<c:when test="${hunter.cityId == city.id }">
								<option value="${city.id}" selected="selected">${city.name}</option>
							</c:when>
							<c:otherwise>
								<option value="${city.id}">${city.name}</option>
							</c:otherwise>
						</c:choose>
					</c:forEach>
				</select>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>从业时间</label>
					<div class="ui input">
						<input type="text" name="workage" id="workage"
							placeholder="请输入从业时间（仅数字）" value="${hunter.workage}">年
					</div>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>个人介绍</label>
					<div class="ui input">
						<input type="text" name=advantage id="advantage"
							   placeholder="请输入个人介绍" value="${hunter.advantage}">
					</div>
				</div>

				<p>2.基本信息</p>
				<div class="field" id="service" style="display: none">
					<label><span style="color: red">*</span>服务内容</label>
					<select name="orderDesc" id="orderDesc" multiple="" class="ui fluid normal dropdown1">
						<c:forEach items="${orderDesc}" var="desc">
							<option value="${desc.id}" >${desc.name}-￥${desc.spec}/${desc.unit}</option>
						</c:forEach>
					</select>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>擅长领域1</label> <select class="ui search  dropdown"
						name="majordomain1" id="majordomain1">
						<option value="">请输入擅长领域</option>
						<c:forEach items="${domains}" var="dm">
							<c:choose>
								<c:when test="${dm.id == hunter.majordomain1 }">
									<option value="${dm.id}" selected="selected">${dm.name}</option>
								</c:when>
								<c:otherwise>
									<option value="${dm.id}">${dm.name}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
					</select>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>擅长领域2</label> <select class="ui search  dropdown"
						name="majordomain2" id="majordomain2">
						<option value="">请输入擅长领域</option>
						<c:forEach items="${domains}" var="dm">
							<c:choose>
								<c:when test="${dm.id == hunter.majordomain2 }">
									<option value="${dm.id}" selected="selected">${dm.name}</option>
								</c:when>
								<c:otherwise>
									<option value="${dm.id}">${dm.name}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
					</select>
				</div>
				<div class="field">
					<label><span style="color: red">*</span>擅长领域3</label> <select class="ui search  dropdown"
						name="majordomain3" id="majordomain3">
						<option value="">请输入擅长领域</option>
						<c:forEach items="${domains}" var="dm">
							<c:choose>
								<c:when test="${dm.id == hunter.majordomain3 }">
									<option value="${dm.id}" selected="selected">${dm.name}</option>
								</c:when>
								<c:otherwise>
									<option value="${dm.id}">${dm.name}</option>
								</c:otherwise>
							</c:choose>
						</c:forEach>
					</select>
				</div>


				<div class="field">
					<label><span style="color: red">*</span>擅长职能</label>
					<select name="bestdomain" id="bestdomain" multiple="" class="ui fluid normal dropdown">
                            <option value="">擅长智能</option>
                            <option value="C-level">C-level</option>
                            <option value="销售/商务/培训">销售/商务/培训</option>
                            <option value="市场/产品">市场/产品</option>
                            <option value="客户服务/技术支持">客户服务/技术支持</option>
                            <option value="工厂">工厂</option>
                            <option value="研发">研发</option>
                            <option value="临床试验/注册/医学事务">临床试验/注册/医学事务</option>
                            <option value="采购/物料/供应链管理">采购/物料/供应链管理</option>
                            <option value="大健康投资">大健康投资</option>
                            <option value="IT/互联网">IT/互联网</option>
                            <option value="人力资源">人力资源</option>
                            <option value="财务/审计/税务">财务/审计/税务</option>
                            <option value="公共/媒介">公共/媒介</option>
                        </select>
				</div>


<%--				<div class="field">--%>
<%--					<label>备注</label>--%>
<%--					<div class="ui input">--%>
<%--						<input type="text" name="comment" id="comment" placeholder="请输入备注"--%>
<%--							value="${hunter.comment}">--%>
<%--					</div>--%>
<%--				</div>--%>


				<input type="hidden" name="hunterid" id="hunterid"
					value="${hunter.id}" /> <input type="hidden" name="phone"
					id="phone" placeholder="请输入姓名" value="${hunter.phone}">
			</form>
		</div>

		<div class="ui segment" id="choice-buttons">
			<div class="fluid ui button" id="next">保存</div>
		</div>
	</div>

	<script src="${ctx}/resources/jweixin-1.0.0.js"></script>
	<script type="text/javascript">
wx.config({
    debug: false, 
    appId: "${config.appid}",  
    timestamp: ${config.currenttimestamp},  
    nonceStr: "${config.nonceStr}", 
    signature: "${config.signatureStr}", 
    jsApiList: ['checkJsApi',
        'onMenuShareTimeline',
        'onMenuShareAppMessage',
        'onMenuShareQQ',
        'onMenuShareWeibo',
        'hideOptionMenu',
        'closeWindow']  
}); 

    var handler = { 
        activate: function() { 
            $(this).addClass('active').siblings().removeClass('active'); 

            if($(this).attr('id') == 'closeit') {
                wx.closeWindow();
            }

            if($(this).attr('id') == 'next') {
                var name = $("#name").val();
                var majordomain1  = $("#majordomain1").val();
                var majordomain2  = $("#majordomain2").val();
                var majordomain3  = $("#majordomain3").val();
                var workage   = $("#workage").val();
                var advantage = $("#advantage").val();
                var phone  = $("#phone").val();
                var email  = $("#cemail").val();
                var hunterid  = $("#hunterid").val();
                // var comment   = $("#comment").val();
                var cityid    = $("#cityId").val();
                var idnumber  = $("#idnumber").val();
                var englishname  = $("#englishname").val();
                var bestdomain  = $("#bestdomain").val();
                var roleIds=$("input[name='roleIds']:checked").val();
				var orderDesc = null;
                if(roleIds != 0){
					orderDesc = $("#orderDesc").val();
				}


                if(!bestdomain || bestdomain=="") {
                  alert("您必须输入您的擅长职能");
                  return false;
	              }
				if(!roleIds) {
					alert("您必须选择账号类型");
					return false;
				}
	              if(bestdomain.length > 100) {
	                  alert("您输入的擅长智能太长");
	                  return false;
	             }
                if(!name || name=="") {
                    alert("您必须输入您的名字");
                    return false;
                }
                if(name.length > 40) {
                    alert("您输入的名字太长");
                    return false;
                }
                if(!englishname || englishname=="") {
                    alert("您必须输入您的英文名");
                    return false;
                }
                if(englishname.length > 50) {
                    alert("您输入的英文名太长");
                    return false;
                }
                if(!idnumber || idnumber=="") {
                    alert("您必须输入您的身份证");
                    return false;
                }
                if(idnumber.length > 18) {
                    alert("您输入的身份证太长");
                    return false;
                }

                
                if(!majordomain1) {
                    alert("您必须选择一个擅长领域1");
                    return false;
                }
                if(!majordomain2) {
                    alert("您必须选择一个擅长领域2");
                    return false;
                }
                if(!majordomain3) {
                    alert("您必须选择一个擅长领域3");
                    return false;
                }
                if(!workage) {
                    alert("您必须输入从业时间");
                    return false;
                }
               
                if(!/^[0-9]+$/.test(workage) || workage < 0 || workage > 60) {
                    alert("您必须输入从业时间"); 
                    return false;
                }
                
                if(!advantage) {
                    alert("您必须输入优势/专长");
                    return false;
                }
               
                if(!email) {
                    alert("您必须输入电子邮箱");
                    return false;
                }
                var re = /[A-Z0-9._%+-]+@[A-Z0-9.-]+.[A-Z]{2,4}/igm;
                if(!re.test(email)) {
                    alert("您必须输入合格的电子邮箱");
                    return false;
                }

                var that = this;

                var postUrl = '${ctx}/wechat/hunter/create.do';
                var param = {};
                param['name']  = name;
                param['englishname']  = englishname;
                param['idnumber']  = idnumber;
                param['cityId']  = cityid;
                param['majordomain1'] = majordomain1;
                param['majordomain2'] = majordomain2;
                param['majordomain3'] = majordomain3;
                param['workage']  = workage;
                param['advantage'] = advantage;
                param['email']  = email;
                param['phone']  = phone;
                param['roleIds'] = roleIds;
                if (hunterid) { 
                    param['id'] = hunterid;
					var b = window.confirm("提交个人信息后，账号需重新认证审核，预计需要1-5个工作日，是否确定提交个人信息？");
					if (!b) {
						return ;
					}
                }
               
               param['serviceTags']= "";
               var srvtags = $('.tag.teal');
               srvtags.each(function(index){
                 param['serviceTags']=param['serviceTags']+ ',' +$(this).text();
               }); 
               
               var bestdomain = $('#bestdomain :selected');
               param['bestdomain']="";
               bestdomain.each(function () {
            	   param['bestdomain']=param['bestdomain']+ ',' +$(this).text();
               });

				// orderDesc.each(function () {
				// 	param['orderDesc']=param['orderDesc']+ ',' +$(this).text();
				// });

				param['orderDesc'] = orderDesc;

                $.ajax({
                    url: postUrl,
                    type: "POST",
                    data: param,
					traditional: true,
                    success: function(data){
                        if(data.errorcode=="0") {
							alert("操作成功！");
							wx.closeWindow();
                            return;
                        } else if(data.errorcode=="1") {
                            alert(data.msg);
                            location.href = '${ctx}/wechat/hunter/main.page';
                            return;
                        } else{
                            alert(data.msg);
                            $(that).removeClass('disabled');
                        }
                    },
                    error: function() {
                        alert("服务出错，请稍后尝试");
                        $(that).removeClass('disabled');
                    }
                });
            }
        } 
    };

    
   var tag = {activate:function(){
                if($(this).hasClass('teal')){
                  $(this).removeClass('teal'); 
                }else{
                  $(this).addClass('teal'); 
                }
              }
  		 };

	function selectApplyRoleType(obj){
		if(obj.id=="hunter"){
			$('#service').hide();
		}else{
			$('#service').show();
		}
	}
   
    $(document).ready(function() { 
    	var domainStr="${hunter.bestdomain}";
    	var roleIds = ${hunter.roleIds};
    	if(roleIds != 0){
			$('#service').show();
		};
    	if(domainStr!=null&&domainStr.length>0){
    		var domainList=new Array();
    		if(domainStr.indexOf(",")!=-1){
    			var strArr=domainStr.split(",");
    			$.each(strArr,function(index,item){
    				domainList.push(item);
    			});
    		}else{
    			domainList.push(domainStr);
    		}
    		
    		$.each(domainList,function(index,str){
    			if(str!=null&&str.length>0){
    				$("#bestdomain option").each(function(index2,item2){
        				// console.log($(item2).val());
        				if(str==$(item2).val()){
        					$(this).prop("selected",true);
        				}
        			});
    			}
    		});
    		
    	}

		var orderDesc="${orderDescOwner}";
		if(orderDesc!=null&&orderDesc.length>0){
			$.each(JSON.parse(orderDesc),function(index,item){
				$("#orderDesc option").each(function(index2,item2){
					if(item==parseInt($(item2).val())){
						$(this).prop("selected",true);
					}
				});
			});
		}

		var tags="${hunter.serviceTags}";
		if(tags!=null&&tags.length>0) {
			var tagList = new Array();
			if (tags.indexOf(",") != -1) {
				var strArr = tags.split(",");
				$.each(strArr, function (index, item) {
					if (item != '') {
						tagList.push(item);
					}
				});
				console.log(tagList);
				$.each(tagList,function(index,str) {
					if (str == '简历修改') {
						$('#a').addClass('teal');
					}
					if (str == '面试辅导') {
						$('#b').addClass('teal');
					}
					if (str == '薪酬分析') {
						$('#c').addClass('teal');
					}
					if (str == '职业规划') {
						$('#d').addClass('teal');
					}
					if (str == '离职咨询') {
						$('#e').addClass('teal');
					}
				})
			}

		}
    	// var roleIds=document.getElementById("roleIds").value;
    	// //$("input[name='roleIds'][value='"+roleIds+"'").attr("checked",true);
    	// $("input[type=radio]").attr("checked",roleIds);
		var val=$("#roleVal").val();   
		$("input[type=radio][name='roleIds'][value='"+val+"']").attr("checked",'checked');
    	
        $('.ui.fluid.normal.dropdown').dropdown({
            allowAdditions: true,
            maxSelections: 3
        });
		$('.ui.fluid.normal.dropdown1').dropdown({
			allowAdditions: true,
			maxSelections: 10
		});
        
    	 $('.button').on('click', handler.activate);

    	 $('.tag').on('click', tag.activate);
     
    	 wx.ready(function() { 
     		wx.hideOptionMenu();
     	});
     
    });

</script>
</body>
</html>